#!/bin/bash

echo "🔧 开始修复部署配置..."

# 检查当前目录
if [ ! -f "package.json" ]; then
    echo "❌ 错误: 请在 frontend-admin 目录下运行此脚本"
    exit 1
fi

echo "📦 清理旧的构建文件..."
rm -rf dist

echo "🔨 重新构建项目..."
npm run build

if [ $? -ne 0 ]; then
    echo "❌ 构建失败"
    exit 1
fi

echo "✅ 构建成功"

echo "🚀 部署到后端..."
npm run deploy

if [ $? -ne 0 ]; then
    echo "❌ 部署失败"
    exit 1
fi

echo "🎉 修复完成！"
echo "📍 访问地址: https://offgrid.vip.hnhxzkj.com/admin/"
echo "📁 静态资源地址: https://offgrid.vip.hnhxzkj.com/admin-static/"
echo "💡 如果仍有问题，请清除浏览器缓存后重试"
